<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核订单页面</title>
    <script src="js/axios.min.js"></script>
    <script src="js/jquery-1.11.3.min.js"></script>
    <script src="js/vue.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/vue-router.js"></script>
    <link rel="stylesheet" href="layui/css/layui.css"/>
    <link rel="stylesheet" href="css/goods.css"/>
    <link rel="stylesheet" href="/static/build/layui.css" media="all">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">通过订单</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">驳回订单</a>
</script>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    layui.use('table', function(){
        var table = layui.table;

        table.render({
            elem: '#test'
            ,url:'http://47.94.138.204:7790/order/checkallorder'
            ,title: '订单数据表'


            /*

            [
            {"usermame":"11","id":"1212"},
            {"usermame":"11","id":"1212"},
            {"usermame":"11","id":"1212"},
            {"usermame":"11","id":"1212"},
            ]

            * */

            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'oid', title:'订单编号', width:100, fixed: 'left', unresize: true, sort: true}
                ,{field:'gid', title:'商品编号', width:100, fixed: 'left', unresize: true, sort: true}
                ,{field:'otime', title:'下单时间', width:190, edit: 'text'}
                ,{field:'num', title:'商品数量', width:100, edit: 'text'}
                ,{field:'price', title:'商品总价', width:100, edit: 'text', sort: true}
                ,{field:'dprice', title:'优惠钱数', width:100, edit: 'text', sort: true}
                ,{field:'rprice', title:'实付价格', width:100, edit: 'text', sort: true}
                ,{field:'uid', title:'用户id', width:100, edit: 'text', sort: true}
                ,{field:'ostate', title:'订单状态', width:100, edit: 'text', sort: true}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:180}
            ]]
            ,page: true
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('确认驳回订单', function(index){
                    obj.del();
                    $.ajax({
                        type:"GET",
                        url:"http://47.94.138.204:7790/order/refuseorder?oid=" + obj.data.oid ,
                        success:function(data){
                            alert("http://127.0.0.1:7747/order/refuseorder?oid=" + obj.data.oid)
                        },
                    });
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                layer.confirm('确认通过订单', function(index){
                    $.ajax({
                        type:"GET",
                        url:"http://47.94.138.204:7790/order/acceptorder?oid=" + obj.data.oid ,
                        success:function(data){
                            alert("http://127.0.0.1:7747/order/acceptorder?oid=" + obj.data.oid)
                        },
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>

</body>
</html>